﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
public partial class Form_TimKiem : System.Web.UI.Page
{
    GetData getData;
    protected void Page_Load(object sender, EventArgs e)
    {
        GetSanPhamByMaLoaiSP();
    }

    public void GetSanPhamByMaLoaiSP()
    {
        getData = new GetData();
        string tenSp = Request.QueryString["TenSp"].ToString();
        List<SanPham> listResult = getData.LoadSPByName(tenSp);
        if (listResult.Count > 0)
        {
            GridSanPham.DataSource = listResult;
            GridSanPham.DataBind();
        }
        else
        {
            Label1.Text = "Hiện chưa có sản phẩm nào trong mục này!";
        }
    }

    protected void GridBooks_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        int masp = (int)int.Parse(Request.QueryString["SanPham"].ToString());
        GridSanPham.PageIndex = e.NewPageIndex;
        GridSanPham.DataSource = getData.GetSanPham(masp);
        GridSanPham.DataBind();
    }

    protected void GridBooks_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        Response.Redirect("AddToGioHang.aspx?MaSP=" + ((Label)GridSanPham.Rows[e.NewSelectedIndex].FindControl("lblMaSP")).Text + "&TenSP=" + ((Label)GridSanPham.Rows[e.NewSelectedIndex].FindControl("lblTenSp")).Text + "&DonGia=" + ((Label)GridSanPham.Rows[e.NewSelectedIndex].FindControl("lblPrice")).Text + "&LinkHinh=" + ((Label)GridSanPham.Rows[e.NewSelectedIndex].FindControl("lblTenHinh")).Text);
    }
    protected void GridSanPham_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}